package com.iecas.handler;

import cn.hutool.core.util.ObjectUtil;
import com.iecas.context.GlobalContext;
import com.iecas.context.ServerContext;
import com.iecas.entity.Tank;
import com.iecas.entity.User;
import com.iecas.enums.BizEnum;
import com.iecas.enums.Direction;
import com.iecas.enums.ResponseEnum;
import com.iecas.launch.Client;
import com.iecas.launch.Server;
import com.iecas.request.JoinReq;
import com.iecas.request.MoveReq;
import com.iecas.request.Root;
import com.iecas.response.BaseResponse;
import com.iecas.response.JoinResp;
import com.iecas.response.MoveResp;
import com.iecas.utils.OnlineManager;
import com.iecas.utils.SocketChannelManager;

import java.nio.channels.SocketChannel;

public class MoveReqHandler extends BaseHandler {

    @Override
    BaseResponse handle(Root baseRequest, Server server, Client client, SocketChannel socketChannel) {
        MoveReq request = (MoveReq) baseRequest;
        String token = request.getToken();
        boolean[] keys = request.getKeys();
        Direction direction = request.getDirection();

        Tank tank = GlobalContext.getServerContext().getTank(token);
        tank.updatePlayer(keys,direction);

        MoveResp resp = new MoveResp();
        resp.setStatus(ResponseEnum.SUCCESS.getCode());
        resp.setCode(BizEnum.MOVE_RESP.getCode());
        return resp;
    }
}
